package com.foxzzz.temporary;

public class Solution7 {
    public int reverse(int x) {
        int result=0;
        int digit=1;
        while (x/10!=0){
            //判断溢出
            if((result*10+x%10-x%10)/10!=result)
                return 0;
            result=result*10+x%10;
            x/=10;
            digit++;
        }
        //判断溢出
        if((result*10+x%10-x%10)/10!=result)
            return 0;
        result=result*10+x;
        return result;
    }

    public static void main(String[] args) {
        System.out.println(new Solution7().reverse(2147483647));
    }
}
